package thread;


import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 线程池的使用
public class Demo34 {
    public static void main(String[] args) {
        // 最普通的线程 可以动态的创建线程数目
//        ExecutorService service = Executors.newCachedThreadPool();
        // 核心线程是固定的
        ExecutorService service = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 10000; i++) {
            int id = i;
            service.submit(new TimerTask() {
                @Override
                public void run() {
                    System.out.println("hello " + id + ", thread:" + Thread.currentThread().getName());
                }
            });
        }

//        Executors.newSingleThreadExecutor(); // 单个线程
//        Executors.newScheduledThreadPool(10); // 延迟创建线程
    }
}
